package com.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ws.soap.client.SoapFaultClientException;

import com.pentalog.bo.ExSoapClient;
import com.pentalog.domain.BookResponse;

public class ExClient {
	public static void main(String[] args) {
		soapServiceTest();
//		restServiceTest();
	}

	public static void restServiceTest(){
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"applicationContext.xml");
		ExSoapClient client = (ExSoapClient) ctx.getBean("exClientImpl");
		BookResponse BookResponse = null;
		try {
			String id = "REST123";
			BookResponse = client.getBookRest(id);
			System.out.println("\tBook Response " + makeString(BookResponse));
		} catch (SoapFaultClientException se) {
			System.out.println("\t" + se.getMessage());
		}
    }
	public static void soapServiceTest(){
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"applicationContext.xml");
		ExSoapClient client = (ExSoapClient) ctx.getBean("exClientImpl");
		BookResponse BookResponse = null;
		try {
			String code = "A11";
			BookResponse = client.getBook(code);
			System.out.println("\tBook Response " + makeString(BookResponse));
		} catch (SoapFaultClientException se) {
			System.out.println("\t" + se.getMessage());
		}
	}

	private static String makeString(BookResponse p) {
		return "[item=" + p.getItemCode() + ", bookname=" + p.getBookName()
				+ ", author=" + p.getAuthor() + "]";
	}
}
